<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>登录</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="static/css/amazeui.css" />
		<link href="static/css/dlstyle.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />	
		
	</head>

	<body> 

		<div class="login-boxtitle" style="height: 100px;">
			<div class="logoBig">
				<img src="static/images/logo.png" style="margin-left: 0px ; height: 100px;">
			</div> 
		</div>

		<div class="login-banner" id="container" >
			<div class="login-main" >
				<div class="login-banner-bg"><span></span><img src="static/images/big.jpg" /></div>
				<div class="login-box" style="margin-top: 20px;">

					<h3 class="title">登录商城</h3>
					<!-- 显示提示信息 -->
					<h5 :style="colorStyle" id="tips">{{tips}}&nbsp;</h5>
					<div class="clear"></div>

					<div class="login-form"  style="background: none; margin-top: 15px;">
						<form>
							<div class="user-name"  style="margin-top: 20px;">
								<label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
								<input type="text" id="user" name="" v-model="username" @keyup="checkInfo" placeholder="邮箱/手机/用户名">
							</div>
							<div class="user-pass"  style="margin-top: 20px;">
								<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
								<input type="password" id="password" name="" v-model="password" @keyup="checkInfo" placeholder="请输入密码">
							</div>
						</form>
					</div>

					<div class="login-links" >
						<label for="remember-me"><input id="remember-me" type="checkbox">记住密码</label>
						<a href="#" class="am-fr">忘记密码</a>
						<br />
					</div>
					<div class="am-cf">
						<input @click="doSubmit" type="button" name="" value="登 录" class="am-btn am-btn-primary am-btn-sm">
					</div>
					<div class="am-cf">
						<input type="button" onclick="javascript:window.location.href='register.html'" value="注 册" class="am-btn am-btn-default am-btn-sm">
					</div>
					<div class="partner">
						
					</div>

				</div>
			</div>
		</div>

		<div class="footer ">
			<div class="footer-hd ">

			</div>
			<div class="footer-bd ">
				<p>
					<a href="# ">联系我们</a>
					<a href="# ">网站地图</a>
				</p>
			</div>
		</div>
		<script src="static/js/vue.js"></script>
		<script src="static/js/axios.min.js"></script>
		<script src="static/js/cookie_utils.js"></script>
		<script src="static/js/utils.js"></script>
		<script>
			var baseUrl = "http://localhost:8080/";
			var vm = new Vue({
				el:"#container",
				data:{
				    username:"",
					password:"",
                    colorStyle:"color:red",
					tips:"",
					isRight:false,
                    returnUrl:null,
					pid:0,
					sid:0,
					num:1
				},
				created:function (){
                    //1.当从商品详情页跳转到登录页面时，并获取显示提示信息（url）
                    this.tips = getUrlParam("tips");
                    this.pid = getUrlParam("pid");
                    this.sid = getUrlParam("sid");
                    this.num = getUrlParam("num");
                    this.returnUrl = getUrlParam("returnUrl");
                    console.log(this.returnUrl)
				},
				methods:{
				    doSubmit:function () {
						if (vm.isRight){
						    //发送请求
							var url = baseUrl+"user/login";
							axios.get(url,{params:{
							    username: vm.username, password: vm.password,
								}}).then(function (res) {
                                console.log(res);
                                var vo = res.data;
                                if (vo.code==10000){
                                    //登录成功，则把token存储到cookie
									setCookieValue("token",vo.msg);
									//将用户信息保存到cookie
                                    console.log(vo);
                                    console.log(vo.data);
                                    setCookieValue("username",vo.data.username);
                                    setCookieValue("userImg",vo.data.userImg);
                                    setCookieValue("userId",vo.data.userId);

                                    if (vm.returnUrl==null){
                                        //跳转到首页
                                        //console.log(vm.returnUrl)
                                        window.location.href="index.html";
									}else {
                                        vm.returnUrl = vm.returnUrl+"?m="+Math.random();
                                        if(vm.pid != null){
                                            vm.returnUrl = vm.returnUrl +"&pid="+vm.pid
                                        }
                                        if(vm.sid != null){
                                            vm.returnUrl = vm.returnUrl +"&sid="+vm.sid
                                        }
                                        if(vm.num != null){
                                            vm.returnUrl = vm.returnUrl +"&num="+vm.num
                                        }
                                        window.location.href = vm.returnUrl;
									}
								}else {
                                    vm.tips="账号或密码错误";
								}
                            });
						}else {
                            vm.tips="请输入正确的账号和密码";
						}
                    },
                    checkInfo:function () {
						if (vm.username==""){
						    vm.tips="请输入同户名";
						    vm.isRight=false;
						}else if (vm.username.length<8||vm.username.length>20){
						    vm.tips="用户名在8~20个字符";
                            vm.isRight=false;
						}else {
                            if (vm.password==""){
                                vm.tips="请输入密码";
                                vm.isRight=false;
                            }else if (vm.password.length<6||vm.password.length>18){
                                vm.tips="密码在6~18个字符";
                                vm.isRight=false;
                            }else {
                                vm.tips="";
                                vm.isRight=true;
							}
						}
                    }
				},
			});
		</script>
	</body>
  
</html>